package com.baizan.daka.ui.presenter

import com.baizan.daka.base.BasePresenter
import com.baizan.daka.mvp.model.BannerModel
import com.baizan.daka.ui.contract.*
import com.baizan.daka.mvp.model.VipModel
import com.baizan.daka.mvp.model.bean.BannerBean
import com.baizan.daka.mvp.model.bean.PackageBean
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.rx.Subscriber.CommonSubscriber
import com.baizan.daka.showToast

class PackagePresenter(val mView: PackageContract.View) : BasePresenter(),
    PackageContract.Presenter {
    private val vipModel: VipModel by lazy { VipModel() }
    private val bannerModel: BannerModel by lazy { BannerModel() }

    override fun loadList(CurrentPage: Int) {
        mView.showLoadingDialog()
        vipModel.vipList(CurrentPage)
            .subscribe(object :
                CommonSubscriber<BasePageResponse<PackageBean>>(compositeDisposable) {

                override fun onCallNext(t: BasePageResponse<PackageBean>?) {
                    mView.loadListSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    showToast(e)
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })

    }

    override fun loadBanner() {
        bannerModel.loadHomeBanner()
            .subscribe(object :
                CommonSubscriber<List<BannerBean>>(compositeDisposable) {

                override fun onCallNext(t: List<BannerBean>?) {
                    mView.loadBannerSuccess(t!!)
                }

                override fun onCallError(e: String) {
                    super.onCallError(e)
                    mView.loadBannerFail()
                }

                override fun onCallCompleted() {
                    super.onCallCompleted()
                    mView.hideLoadingDialog()
                }
            })
    }
}

